<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var arr = [7,1,5,3,6,4];
        var maxProfit = function(prices) {
            var max = 0;
            for(let i=0;i<prices.length-1;i++){
                while(prices[i+1]>prices[i]){
                    max += prices[i+1]-prices[i]
                    break;
                }
            }
            return max;
        };
        console.log(maxProfit(arr));
    </script>
</body>
</html>